export default function throttle<T extends (...args: any) => any>(
  fn: T,
  delay = 500,
) {
  let timer: ReturnType<typeof setTimeout> | undefined;
  return function (this: unknown, ...args) {
    if (typeof timer === "number") {
      return;
    }
    timer = setTimeout(() => {
      fn.apply(this, args);
      timer = undefined;
    }, delay);
  } as T;
}
